/**
 * Created by shenyinlin on 2018/6/24.
 */
//资源文件加载器，确保canvas在突破加载完成后再加载
import {Resources} from './Resources.js';
export class ResourceLoader {

    constructor() {
        this.map = new Map(Resources);
        for (let [key, value] of this.map) {
            // const image = new Image();
          const image = wx.createImage();
            //同wx.createImage()
            image.src = value;
            //资源加载
            // console.log('value:'+value);
            this.map.set(key, image);
        }
    }
    onloaded(callback){
        let loadedCount = 0;
        for(let value of this.map.values()){
            value.onload = () =>{
                loadedCount++;
                if(loadedCount>=this.map.size){
                    callback(this.map)
                }
            }
        }
    }

    static create(){
        return new ResourceLoader();
    }

}